﻿using Abp.Dependency;
using GN.Pay.Core.Runtime.Caching;
using RabbitMQ.GNClient;
using StackExchange.Redis;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GN.Pay.Core.Tasks.Queue.Impl
{
    /// <summary>
    /// 生产队列
    /// </summary>
    class ProduceQueue : AQueue, IProduceQueue, ITransientDependency
    {
        public ProduceQueue(string name)
            : base(name)
        {
        }       

        /// <summary>
        /// 发布
        /// </summary>
        /// <param name="message"></param>
        /// <param name="delayConsumer"></param>
        public void Publish(ObjectMessage message, TimeSpan? delayConsumer = null)
        {
            var channel = GetChannel();
            channel.Publish(message, delayConsumer);
        }

        /// <summary>
        /// 异步发布
        /// </summary>
        /// <param name="message">消息</param>
        public async Task PublishAsync(ObjectMessage message, TimeSpan? delayConsumer = null)
        {
            await Task.Run(() => { this.Publish(message, delayConsumer); });
        }
    }
}
